/**
* 版权声明：厦门睿商网络科技有限公司 版权所有 违者必究
* 日    期：2020-07-10
*/
package com.rzico.basics.entity;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.rzico.annotation.IgnoreSwaggerParameter;
import com.rzico.basics.model.MapPoint;
import lombok.Data;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import io.swagger.annotations.ApiModelProperty;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

/**
 * <pre>
 *   送货线路数据库对象
 * </pre>
 * @author Rzico Boot
 * @version 1.0
 */
@Data
@JsonIgnoreProperties(value = {"handler"})
@JsonInclude(JsonInclude.Include.NON_NULL)
@Table(name = "wx_map_line")
public class MapLine{
    
    @Id
    @ApiModelProperty(value = "" )
    protected Long id;

    @ApiModelProperty(value = "创建日期" )
    protected java.util.Date createDate;

    @ApiModelProperty(value = "修改日期" )
    protected java.util.Date modifyDate;

    @ApiModelProperty(value = "线路名称" )
    protected String name;

    @ApiModelProperty(value = "所属仓库" )
    protected Long shopId;

    @ApiModelProperty(value = "地图围栏" )
    protected String points;

    @ApiModelProperty(value = "送货员" )
    protected String shippingEmployeeId;

    @ApiModelProperty(value = "企业" )
    protected Long enterpriseId;

    @IgnoreSwaggerParameter
    @JsonIgnore
    protected Shop shop;

    public String getShopName() {
        Shop shop = getShop();
        if (shop!=null) {
            return shop.getName();
        } else {
            return null;
        }
    }

    public List<MapPoint> getMapPoint() {
        if (getPoints()!=null) {
            List<MapPoint> data = new ArrayList<>();
            JSONArray ja = JSON.parseArray(getPoints());
            for (int i=0;i<ja.size();i++) {
                JSONObject jo = ja.getJSONObject(i);
                MapPoint mp = new MapPoint();
                mp.setM(jo.getDouble("M"));
                mp.setO(jo.getDouble("O"));
                mp.setLat(jo.getDouble("lat"));
                mp.setLng(jo.getDouble("lng"));
                data.add(mp);
            }
            return data;
        } else {
            return null;
        }
    }

    public void setMapPoint(List<MapPoint> value) {
        if (value==null) {
            setPoints(null);
        } else {
            setPoints(JSON.toJSONString(value));
        }
    }

}
